﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;

public static class ObjectPoolExtensions
{
    public static void Recycle(this GameObject obj)
    {
        ObjectPool.Recycle<Transform>(obj.transform);
    }

    public static void Recycle<T>(this T obj) where T: Component
    {
        ObjectPool.Recycle<T>(obj);
    }

    public static T Spawn<T>(this T prefab) where T: Component
    {
        return ObjectPool.Spawn<T>(prefab, Vector3.zero, prefab.transform.rotation);
    }

    public static GameObject Spawn(this GameObject prefab, Vector3 position)
    {
        return ObjectPool.Spawn<Transform>(prefab.transform, position, prefab.transform.rotation).gameObject;
    }

    public static T Spawn<T>(this T prefab, Vector3 position) where T: Component
    {
        return ObjectPool.Spawn<T>(prefab, position, prefab.transform.rotation);
    }

    public static GameObject Spawn(this GameObject prefab, Vector3 position, Quaternion rotation)
    {
        return ObjectPool.Spawn<Transform>(prefab.transform, position, rotation).gameObject;
    }

    public static T Spawn<T>(this T prefab, Vector3 position, Quaternion rotation) where T: Component
    {
        return ObjectPool.Spawn<T>(prefab, position, rotation);
    }
}

